import { getDetailDataApi } from "@/api/waybillManagement/workOrder";
import { reactive, ref } from "vue";
export default function InitHook() {
  const formState = ref<Partial<BusinessWorkOrder.DetailForm>>({
    pointData: [],
    shipmentData: [],
    questionDesc: "",
    questionScope: "",
    questionType: ""
  });
  const loading = ref<boolean>(false);
  const dialogOpts = reactive<Base.DialogOpts>({
    title: "修改送货仓库",
    width: "720px",
    type: 1,
    passData: {},
    component: "",
    visible: false
  });
  const drawerOpts = reactive<Base.DrawerOpts>({
    title: "修改送货仓库",
    width: "720px",
    type: 1,
    passData: {},
    component: "",
    visible: false
  });
  const init = async (id: string) => {
    loading.value = true;
    return getDetailDataApi(id)
      .then((res: any) => {
        const { code, data } = res;
        if (code === 200) {
          formState.value = data;
        }
      })
      .finally(() => {
        loading.value = false;
      });
  };

  // const sumMethod = (data: any, field: any) => {
  //   let count = 0;
  //   data.map((t: any) => {
  //     count += (Number(t[field]) * 100) / 100;
  //   });
  //   return count.toFixed(2);
  // };

  // const footerData = ({ data, columns }: any) => {
  //   return [
  //     columns.map((t: any, columnIndex: number) => {
  //       if (columnIndex === 0) {
  //         return "总计";
  //       }
  //       if (["boxWeight"].includes(t.field)) {
  //         return sumMethod(data, t.field);
  //       }

  //       if (["volumeWeight"].includes(t.field)) {
  //         return sumMethod(data, t.field);
  //       }

  //       return "";
  //     })
  //   ];
  // };
  return {
    formState,
    dialogOpts,
    init,
    loading,
    drawerOpts
    // footerData
  };
}
